package com.appspot.rsp.service;

import java.io.UnsupportedEncodingException;
import java.util.Properties;
import java.util.logging.Logger;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class RspEmailService {
	private static final Logger log = Logger.getLogger(RspEmailService.class
			.getName());

	public void sendContactMail(String fromAddress, String fromName,
			String toAddress, String toName, String subject, String message) {
		Properties props = new Properties();
		props.setProperty("mail.smtp.host", "smtp.google.com");
		props.setProperty("mail.user", "");
		props.setProperty("mail.password", "");
		
		Session session = Session.getDefaultInstance(props, null);

		try {
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress(fromAddress, fromName));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
					toAddress, toName));
			msg.setSubject(subject);
			msg.setText(message);
			Transport.send(msg);

		} catch (AddressException e) {
			log.throwing(RspEmailService.class.getName(), "sendContactMail", e);
		} catch (MessagingException e) {
			log.throwing(RspEmailService.class.getName(), "sendContactMail", e);
		} catch (UnsupportedEncodingException e) {
			log.throwing(RspEmailService.class.getName(), "sendContactMail", e);
		}
	}
}
